{"ast":null,"code":"var _jsxFileName = \"/data/messenger.client/src/containers/Dialogs.tsx\",\n  _s = $RefreshSig$();\nimport React from \"react\";\nimport { Dialogs as DialogList } from \"../components/\";\nimport { getOtherUserForNotMultiChat } from \"../utils/Membership\";\nimport { observer } from \"mobx-react-lite\";\nimport { Context } from \"../index\";\nimport { getUserName } from \"../utils/User\";\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\nconst Dialogs = () => {\n  _s();\n  const {\n    store\n  } = React.useContext(Context);\n  const [chatsList, setChatsList] = React.useState({\n    items: []\n  });\n  const [inputValue, setInputValue] = React.useState('');\n  const [sort, setSort] = React.useState(chatsList.items);\n  const [onload, setOnload] = React.useState(false);\n  React.useEffect(() => {\n    if (typeof store.getChats() !== undefined) {\n      store.getChatsFromAPI().then(() => setOnload(true));\n    }\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n  React.useEffect(() => {\n    setChatsList(store.getChats());\n    chatsList.items && setSort(chatsList.items);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [store.getChats()]);\n  const onChangeInput = function () {\n    let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';\n    if (chatsList.items.length > 0) {\n      setSort(chatsList.items.filter(dialog => dialog.multiChat ? dialog.name.toLowerCase().indexOf(value.toLowerCase()) >= 0 : getUserName(dialog.membership ? getOtherUserForNotMultiChat(store, dialog.membership) : store.getProfile()).toLowerCase().indexOf(value.toLowerCase()) >= 0));\n    }\n    setInputValue(value);\n  };\n  if (onload) {\n    return /*#__PURE__*/_jsxDEV(DialogList, {\n      chatsList: {\n        items: sort\n      },\n      onSearch: onChangeInput,\n      inputValue: inputValue\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 52,\n      columnNumber: 16\n    }, this);\n  } else {\n    return /*#__PURE__*/_jsxDEV(DialogList, {\n      chatsList: {\n        items: []\n      },\n      onSearch: onChangeInput,\n      inputValue: inputValue\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 58,\n      columnNumber: 16\n    }, this);\n  }\n};\n_s(Dialogs, \"MUWsCyax0mnJLjaAkuiEJ8sJ7Wo=\");\n_c = Dialogs;\nexport default _c2 = observer(Dialogs);\nvar _c, _c2;\n$RefreshReg$(_c, \"Dialogs\");\n$RefreshReg$(_c2, \"%default%\");","map":{"version":3,"names":["React","Dialogs","DialogList","getOtherUserForNotMultiChat","observer","Context","getUserName","store","useContext","chatsList","setChatsList","useState","items","inputValue","setInputValue","sort","setSort","onload","setOnload","useEffect","getChats","undefined","getChatsFromAPI","then","onChangeInput","value","length","filter","dialog","multiChat","name","toLowerCase","indexOf","membership","getProfile"],"sources":["/data/messenger.client/src/containers/Dialogs.tsx"],"sourcesContent":["import React from \"react\";\nimport {Dialogs as DialogList} from \"../components/\";\nimport {ChatsListResponse} from \"../models/response/ChatsListResponse\";\nimport {getOtherUserForNotMultiChat} from \"../utils/Membership\";\nimport {observer} from \"mobx-react-lite\";\nimport {Context} from \"../index\";\nimport {getUserName} from \"../utils/User\";\nimport {ChatsListItem} from \"../models/response/ChatsListItem\";\n\nconst Dialogs:React.FC = () => {\n    const {store} = React.useContext(Context);\n    const [chatsList, setChatsList] = React.useState<ChatsListResponse>({items: []});\n    const [inputValue, setInputValue] = React.useState<string>('');\n    const [sort, setSort] = React.useState(chatsList.items);\n    const [onload, setOnload] = React.useState<boolean>(false);\n\n    React.useEffect(() => {\n        if (typeof store.getChats() !== undefined) {\n            store.getChatsFromAPI().then(() =>\n                setOnload(true)\n            );\n        }\n        // eslint-disable-next-line react-hooks/exhaustive-deps\n    }, []);\n\n    React.useEffect(() => {\n        setChatsList(store.getChats());\n        chatsList.items && setSort(chatsList.items);\n        // eslint-disable-next-line react-hooks/exhaustive-deps\n    }, [store.getChats()]);\n\n    const onChangeInput = (value: string = '') => {\n        if (chatsList.items.length > 0) {\n            setSort(\n                chatsList.items.filter(\n                    (dialog: ChatsListItem) => (\n                        (dialog.multiChat)? dialog.name.toLowerCase().indexOf(value.toLowerCase()) >= 0:\n                            getUserName(\n                                dialog.membership?\n                                    getOtherUserForNotMultiChat(store, dialog.membership):\n                                    store.getProfile()\n                            ).toLowerCase().indexOf(value.toLowerCase()) >= 0\n                    )\n                )\n            );\n        }\n\n        setInputValue(value);\n    };\n\n    if (onload) {\n        return <DialogList\n            chatsList={{items: sort}}\n            onSearch={onChangeInput}\n            inputValue={inputValue}\n        />;\n    } else {\n        return <DialogList\n            chatsList={{items: []}}\n            onSearch={onChangeInput}\n            inputValue={inputValue}\n        />;\n    }\n};\n\nexport default observer(Dialogs);"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAAQC,OAAO,IAAIC,UAAU,QAAO,gBAAgB;AAEpD,SAAQC,2BAA2B,QAAO,qBAAqB;AAC/D,SAAQC,QAAQ,QAAO,iBAAiB;AACxC,SAAQC,OAAO,QAAO,UAAU;AAChC,SAAQC,WAAW,QAAO,eAAe;AAAC;AAG1C,MAAML,OAAgB,GAAG,MAAM;EAAA;EAC3B,MAAM;IAACM;EAAK,CAAC,GAAGP,KAAK,CAACQ,UAAU,CAACH,OAAO,CAAC;EACzC,MAAM,CAACI,SAAS,EAAEC,YAAY,CAAC,GAAGV,KAAK,CAACW,QAAQ,CAAoB;IAACC,KAAK,EAAE;EAAE,CAAC,CAAC;EAChF,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGd,KAAK,CAACW,QAAQ,CAAS,EAAE,CAAC;EAC9D,MAAM,CAACI,IAAI,EAAEC,OAAO,CAAC,GAAGhB,KAAK,CAACW,QAAQ,CAACF,SAAS,CAACG,KAAK,CAAC;EACvD,MAAM,CAACK,MAAM,EAAEC,SAAS,CAAC,GAAGlB,KAAK,CAACW,QAAQ,CAAU,KAAK,CAAC;EAE1DX,KAAK,CAACmB,SAAS,CAAC,MAAM;IAClB,IAAI,OAAOZ,KAAK,CAACa,QAAQ,EAAE,KAAKC,SAAS,EAAE;MACvCd,KAAK,CAACe,eAAe,EA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